#include <iostream>
#include <cstdio>
#include <algorithm>

#define MAXN 1100

using namespace std;

int dp[MAXN];	int win[MAXN];	int lose[MAXN];		int use[MAXN];

int main() {
	int n, x;
	cin >> n >> x;
	for (int i = 1; i <= n; i++){
		scanf("%d%d%d", &win[i], &lose[i], &use[i]);
	}
	for (int i = 1; i <= n; i++){
		for (int j = x; j >= use[i]; j--){
			dp[j] = max (dp[j] + lose[i], dp[j - use[i]] + win[i]);
		}
		for(int j = use[i] - 1; j >= 0; j--){
			dp[j] += lose[i];
		}
	}
	cout << 5 * dp[x] << endl;
	return 0;
}